﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
using StudentHookups.WCF;
using System.IO;

namespace StudentHookups.Account.Profile
{
    public partial class EditProfile : System.Web.UI.Page
    {
        WCF.WCFClient client = new WCFClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 16; i <= 99; i++)
            {
                ddlAge.Items.Add(new ListItem(i.ToString()));
            }
            Guid user = (Guid)Membership.GetUser().ProviderUserKey;
            UserComposite loggedinUser = client.GetUser(user);

            tbFirstname.Text = loggedinUser.Firstname;
            tbLastname.Text = loggedinUser.Lastname;
            ddlAge.Items.FindByText(loggedinUser.Age.ToString()).Selected = true;
            ddlChangeGender.Items.FindByText(loggedinUser.Gender).Selected = true;

            currImg.ImageUrl = loggedinUser.Image;
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (imgUpload.HasFile)
            {
                

                string filename = Path.GetFileName(imgUpload.FileName);
                string[] splitFilename = filename.Split('.');
                string filepath = "/imgs/" + Membership.GetUser().ProviderUserKey + "." + splitFilename[1];

                if (File.Exists(filepath))
                {
                    File.Delete(filepath);
                }
                imgUpload.SaveAs(Server.MapPath(filepath));

            }
        }
    }
}